#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

class Solution {
public:
    bool isNStraightHand(vector<int>& hand, int groupSize) {
        if (hand.size() % groupSize != 0) {
            return false;
        }

        sort(hand.begin(), hand.end());

        multimap<int, int> handMap;
        for (int idx = 0; idx < hand.size(); idx++) {
            if (handMap.count(hand[idx] - 1) == 0) {
                handMap.insert(make_pair(hand[idx], groupSize - 1));
            } else {
                InsertMapProc(handMap, hand[idx]);
            }
            eraseMapProc(handMap);
        }
        return (handMap.size() == 0);
    }

    void InsertMapProc(multimap<int, int>& handMap, int key)
    {
        for (auto it = handMap.begin(); it != handMap.end();) {
            if (it->first == key - 1) {
                handMap.insert(make_pair(key, it->second - 1));
                it = handMap.erase(it);
                break;
            } else {
                it++;
            }
        }
        return;
    }

    void eraseMapProc(multimap<int, int>& handMap)
    {
        for (auto it = handMap.begin(); it != handMap.end();) {
            if (it->second == 0) {
                it = handMap.erase(it);
            } else {
                it++;
            }
        }
        return;
    }
};

int main()
{
    Solution s;
    vector<int> vt{ 2,1 };
    cout << boolalpha << s.isNStraightHand(vt, 2) << endl;
    // multimap<int, int> tmpMap{
    //     {1, 1}, {2, 2}, {3, 3},
    //     {1, 11}, {2, 22}, {3, 33},
    // };

    // for (auto it = tmpMap.begin(); it != tmpMap.end(); it++) {
    //     cout << it->first << " " << it->second << endl;
    // }

    // if (tmpMap.count(2) != 0) {
    //     for (auto it = tmpMap.begin(); it != tmpMap.end();) {
    //         if (it->first == 2) {   
    //             it = tmpMap.erase(it);
    //             break;
    //         } else {
    //             it++;
    //         }
    //     }
    // }

    // cout << "*******" << endl;
    // for (auto it = tmpMap.begin(); it != tmpMap.end(); it++) {
    //     cout << it->first << " " << it->second << endl;
    // }
    return 0;
}